Skip to content

fix(auxiliary/mitmdump): skip stop cleanup when mitmdump is not enabled for task - #103

Closed
karlhiramoto wants to merge 2 commits into
masterfrom
fix/mitmdump-skip-stop-when-disabled
Closed

karlhiramoto wants to merge 2 commits into
masterfrom
fix/mitmdump-skip-stop-when-disabled

Conversation

@karlhiramoto

@karlhiramoto karlhiramoto commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

When the Mitmdump auxiliary module is enabled in auxiliary.conf but mitmdump is not enabled in task.options:

  • Mitmdump.start() previously spawned MitmdumpThread (scanning ports 8001-8080), which exited early in run() without creating mitmdump.pid or enabling firewall rules.
  • MitmdumpThread.stop() unconditionally attempted to read mitmdump.pid (logging ERROR: Error: PID file not found at: .../mitmdump/mitmdump.pid and attaching that error to task.errors) and called rooter("disable_mitmdump", ...).

Changes

  • modules/auxiliary/Mitmdump.py:
    • Parse mitmdump option tokens cleanly in _is_mitmdump_enabled() (supporting bare mitmdump and mitmdump=<truthy> while rejecting 0/no/false/empty values and unrelated substrings) and strip whitespace in _get_netns().
    • Skip spawning MitmdumpThread in Mitmdump.start() when disabled.
    • Synchronize MitmdumpThread.run() and stop() via _state_lock and self.join(timeout=65) so concurrent stop() cannot skip firewall teardown or allow Popen to launch after stop().
    • Handle rooter()'s dict return contract ({"output": ..., "exception": ...}), roll back disable_mitmdump on enable timeout or os.makedirs/Popen failure, wrap process stop in try/finally so disable_mitmdump always runs even on OSError, and reap direct self.proc children without spinning 15s on zombies.
  • tests/test_mitmdump.py:
    • Add 28 unit tests covering option parsing, rooter() dict errors/timeouts, Popen rollback, concurrent run()/stop(), direct child reaping, and os.kill error handling.

Verification

  • ruff check modules/auxiliary/Mitmdump.py tests/test_mitmdump.py
  • ruff format --check modules/auxiliary/Mitmdump.py tests/test_mitmdump.py
  • tests/test_mitmdump.py: 28 passed.

@karlhiramoto
karlhiramoto marked this pull request as ready for review November 27, 2026 09:31

@dsecuma dsecuma left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary: LGTM / Approved ✅

Reviewed VirusTotal/CAPEv2#103 (fix/mitmdump-skip-stop-when-disabled, commit ebc1b16ddc60b64ac3cda2fb7f1986ca337a1dbb).

Verification Summary

  • Logic & Context (modules/auxiliary/Mitmdump.py): _is_mitmdump_enabled accurately parses comma-separated option tokens (rejecting falsy values and substrings) and skips MitmdumpThread creation/port scanning when disabled, eliminating spurious mitmdump.pid errors and disable_mitmdump calls during stop().
  • Concurrency, Reliability & Tests (modules/auxiliary/Mitmdump.py, tests/test_mitmdump.py): Synchronizing run()/stop() with _state_lock and join(timeout=65), handling rooter() dict errors with firewall rollback, reaping direct self.proc children cleanly, and adding 28 unit tests with all CI checks passing (test (3.10), test (3.14), check-changes, cla/google) look solid.

@dsecuma
dsecuma self-requested a review November 27, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants